package com.burst.reptile.modular.web.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.burst.reptile.common.utils.ToolUtil;
import com.burst.reptile.modular.web.entity.ZpWebinfo;
import com.burst.reptile.modular.web.mapper.ZpWebinfoMapper;
import com.burst.reptile.modular.web.service.IZpWebinfoService;

/**
 * <p>
 * 网站信息相关协议 服务实现类
 * </p>
 *
 * @author wujin
 * @since 2020-07-06
 */
@Service
public class ZpWebinfoServiceImpl extends ServiceImpl<ZpWebinfoMapper, ZpWebinfo> implements IZpWebinfoService {

	@Override
	public ZpWebinfo getZpWebinfo(String type) {
		return this.getOne(new QueryWrapper<ZpWebinfo>().eq("wtype", type));
	}

	@Override
	public int add(ZpWebinfo webinfo) {
		String wtype = webinfo.getWtype();
		ZpWebinfo zpWebinfo = getZpWebinfo(wtype);
		int i = 0;
		if(ToolUtil.isNotEmpty(zpWebinfo)) {
			zpWebinfo.setContent(webinfo.getContent());
			zpWebinfo.setContextText(webinfo.getContextText());
			i = this.baseMapper.updateById(zpWebinfo);
		}else {
			i = this.baseMapper.insert(webinfo);
		}
		return i;
	}

}
